//
//  ArriveProduceView.swift
//  DSHCMerchant
//
//  Created by 罗德良 on 2018/4/17.
//  Copyright © 2018年 袋鼠好车. All rights reserved.
//

import UIKit

class ArriveProduceView: UIView {

    typealias sureOrcancleBlock = (_ boolValue:Bool) -> Void
    
    
    @IBOutlet var priceTF: UITextField!

    @IBOutlet var choosePaywayBtn: UIButton!
    
    @IBOutlet var cancleBtn: UIButton!
    
    @IBOutlet var saveBtn: UIButton!
    
    var payway_id = "" //固定 1 会员卡 2 支付宝 3 微信 4 银行卡 5 现金 6 优惠券
    
    var tapSureOrcancle:sureOrcancleBlock?
    
    func callBackBlock(_ block: @escaping sureOrcancleBlock) {
        
        tapSureOrcancle = block
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.frame = CGRect(x:0, y:0, width:ScaleWidth(300),height:ScaleHeight(200));
        self.center = CGPoint(x: kScreenWidth/2, y: kScreenHeight/2)
        self.roundCorner(radius: 5)
    }
    
    class func getArriveProducePopView() -> ArriveProduceView {
        return UIView.creatFromNIB(By: "ArriveProduceView") as! ArriveProduceView
    }
    
    @IBAction func saveBtnPress(_ sender: UIButton) {
        
        if (self.priceTF.text == "") || (self.payway_id == "") {
            MBProgressHUD.alertShow(in: self, message: "请填写完整再提交", hidenAfter: 0.8, mode: MBProgressHUDMode.text)
            return
        }
        if tapSureOrcancle != nil {
            self.tapSureOrcancle!(true)
        }
    }
    
    @IBAction func cancleBtnPress(_ sender: UIButton) {
        if tapSureOrcancle != nil {
            tapSureOrcancle!(false)
        }
    }
    
    @IBAction func choosePaywayBtnPress(_ sender: UIButton) {
        self.endEditing(true)
        BRStringPickerView.showStringPicker(withTitle: "支付方式", dataSource: ["会员卡","支付宝","微信","银行卡","现金","优惠券"], defaultSelValue: "会员卡", isAutoSelect: true) { (str,index) in
            self.choosePaywayBtn.setTitle(str as? String, for: .normal)
            self.payway_id = String(index + 1)
        }
        
    }
}
